<?php
/**
 * Created by PhpStorm.
 * User: lwt
 * Date: 4/22/19
 * Time: 8:38 PM
 */

namespace app\admin\model;

use think\Db;
use think\Model;

class CommodityModel extends Model
{
    public static function addCommodity($data){
        $request = Db::table('tb_commodity')->insert($data);
        return $request;
    }

    public static function deleteCommodity($co_id){
        $msg = Db::table("tb_commodity")->where("co_id",$co_id)->find();
        $isNull = true;
        if (is_array($msg)){
            $isNull = false;
        }
        if ($isNull){
            return 0;
        }else{
            $msg = Db::table('tb_commodity')->delete($co_id);
            return $msg;
        }

    }

    public static function updateCommodity($data){
        $msg = Db::table('tb_commodity')->where('co_id', $data["co_id"])->update($data);
        return $msg;
    }

    public static function selectAllCommodity(){
        $msg = Db::query('select *  from tb_commodity');
        return $msg;
    }

    public static function selectLikeCommodity($data){
        $msg = Db::name('tb_commodity')->where('co_name','like',"%".$data."%")->select();
        return $msg;
    }

    public static function selectCommodityById($co_id){
        $msg = Db::query('select *  from tb_commodity where co_id = ?',[$co_id]);
        return $msg;
    }
}